package development.group;

import state.GameForm;
import state.Graphics;
import state.GroupForm;
import state.Key;
import state.component.MultiTab;
import state.util.Hashtable;
import development.Constants;
import development.DrawUtils;
import development.FrmFriend;
import development.FrmTopLevel;
import development.FrmTopRiskest;

public class FrmGroupFriendAndTop extends GroupForm {
  private MultiTab multiTab;
  private static GameForm singleton;
  public static Hashtable parameters;
  public static GameForm backForm;
  private int selectedTab;
  
  public static GameForm instance() {
    if (singleton == null) {
      singleton = new FrmGroupFriendAndTop();
    }
    return singleton;
  }
  
  public void init(Hashtable parameters1) {
    FrmGroupFriendAndTop.parameters = parameters1;
    multiTab = new MultiTab(this, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT);
    multiTab.addTab("Bạn bè", FrmFriend.instance(), parameters1);
    multiTab.addTab("Đại gia", FrmTopRiskest.instance(), parameters1);
    multiTab.addTab("Cao thủ", FrmTopLevel.instance(), parameters1);
    multiTab.setStyle(Constants.MULTI_TAB_STYLE);
    multiTab.selectTab(selectedTab);
  }
  
  public static void setTab(int index) {
    FrmGroupFriendAndTop frmFriendAndTop = (FrmGroupFriendAndTop) FrmGroupFriendAndTop.instance();
    MultiTab multiTab = frmFriendAndTop.getMultiTab();
    if (multiTab != null) {
      multiTab.selectTab(index);
    }
    frmFriendAndTop.selectedTab = index;
  }
  
  public MultiTab getMultiTab() {
    return multiTab;
  }
  
  public void draw(Graphics g) {
    DrawUtils.drawBackground(g);
  }
  
  public void goBack() {
  }
  
  public void keyReleased(int keyCode) {
    switch (keyCode) {
    case Key.LEFT:
      multiTab.previousTab();
      break;
    case Key.RIGHT:
      multiTab.nextTab();
      break;
    }
  }
  
  public void destroy() {
    multiTab.detroy();
    multiTab = null;
    backForm = null;
    FrmFriend.instance().detroyAll();
    FrmTopRiskest.instance().detroyAll();
    FrmTopLevel.instance().detroyAll();
  }
}
